import 'package:flutter/material.dart';
import 'package:easy_refresh/easy_refresh.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'EasyRefresh Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: EasyRefreshExample(),
    );
  }
}

class EasyRefreshExample extends StatefulWidget {
  @override
  _EasyRefreshExampleState createState() => _EasyRefreshExampleState();
}

class _EasyRefreshExampleState extends State<EasyRefreshExample> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('EasyRefresh')),
      body: EasyRefresh(
        // header: CustomRefreshHeader(
        //     key: Key('刷新'), alignment: Alignment.center),

        footer: ClassicFooter(
          backgroundColor: Color(0xFFF2F4FA),
          readyText: '加载中...',
          processingText: '加载中...',
          processedText: '加载成功',
          noMoreText: '无更多内容，快去发布新活动吧',
          failedText: '加载失败',
          showMessage: false,
          // messageText: DateFormat("MM-dd HH:mm").format(DateTime.now()),
        ),

        onLoad: () async {
          await Future.delayed(Duration(seconds: 2));
        },
        onRefresh: () async {
          // 假设这里是获取数据的逻辑
          // controller.onRefresh();
          await Future.delayed(Duration(seconds: 2));
        },
        child: ListView.builder(
          itemCount: 20,
          itemBuilder: (context, index) {
            return ListTile(title: Text('Item $index'));
          },
        ),
      ),
    );
  }
}
